package com.ztjava.common.tool.push;

import com.jfinal.kit.Ret;
import com.ztjava.core.Constant;

public class ErpWebSocketImp implements PushInterface{
	@Override
	public Ret push(String to, String content) {
		String[] arr = to.split(",");
		if(arr==null||arr.length==0){
			return WebSocketMessage.sendMessage(content);
		}

		int success = 0;
		int error = 0;
		for(String item:arr){
			Ret ret = WebSocketMessage.sendMessage(Integer.parseInt(item), content);
			if(ret.getStr(Constant.RESULT).equals(Constant.ERROR)){
				error = error + 1;
			}else {
				success = success + 1;
			}
		}
		return Ret.create(Constant.RESULT, Constant.SUCCESS).set(Constant.MESSAGE, "成功发送"+success+"条，失败"+error+"条！");
	}

}
